import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.border
import androidx.compose.foundation.defaultScrollbarStyle
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import java.lang.Thread.sleep
import kotlin.concurrent.thread

@Composable
@Preview
fun App() {
    var text by remember { mutableStateOf("Hello, World!") }

    MaterialTheme {
        defaultScrollbarStyle()
        Column(
            Modifier
                .padding(10.dp)
        ) {
            Text(
                modifier = Modifier
                    .size(400.dp, 300.dp)
                    .padding(10.dp)
                    .border(1.dp, Color.LightGray, RoundedCornerShape(4.dp))
                    .verticalScroll(rememberScrollState()),

                text = text,
                style = TextStyle(
                    fontSize = 18.sp,
                    color = Color.DarkGray,
                    fontStyle = FontStyle.Normal,
                    textAlign = TextAlign.Left
                ),
                fontWeight = FontWeight.Medium,


                )

            Button(
                onClick = {
                    thread(start = true) {
                        while (true) {
                            text += "Hello, World!\n"
                            sleep(200)
                        }
                    }
                }
            ) {

            }
        }
    }
}

fun main() = application {
    Window(
        onCloseRequest = ::exitApplication,
        state = WindowState(width = 1280.dp, height = 720.dp),
        resizable = false
    ) {
        App()
    }
}
